<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/24
 * Time: 16:23
 */

namespace app\api\controller;

use app\api\model\DeviceJpush;
use app\api\model\Recommend as RecommendModel;
use app\api\model\Sendcode as CodeModel;
use app\api\model\TransErr;
use app\api\model\User as UserModel;
use app\api\service\Alipay;
use app\api\service\User as UserService;
use app\api\service\Wechat;
use app\crm\model\Withdrawal;
use think\Db;
use think\Exception;


class User
{
    /**
     * 配置参数
     * @return \think\response\Json
     */
    public function configParams()
    {
        $url = Db::name('config_param')->where('key', 'url')->value('value_str');
//        $random = get_rand_char(20);
        $data = [
            'withdraw_multiple' => config('config.提现_倍数'),
            'withdraw_deduction' => config('config.提现_扣除_转奖金池'),
            'withdraw_min' => config('config.提现_起提'),
            'give_gold_level_1' => config('config.会员_赠送_level_1'),//赠送金币_普通
            'give_gold_level_2' => config('config.会员_赠送_level_2'),//赠送金币_高级
            'gold_price' => config('config.金币_单价'),
            'gold_min' => config('config.金币_起充'),
            'price_level_1' => config('config.会员_价格_level_1'),
            'price_level_2' => config('config.会员_价格_level_2'),
            'promoter_price' => config('config.脉大师_价格'),
            'url' => $url,
        ];
        return json(['errorCode' => 0, 'data' => $data]);
    }

    //注册时信息获取推荐人信息
    public function getRecommender()
    {
        $request_code = input('get.request_code');
        if (empty($request_code)) {
            return json(['errorCode' => 1, 'msg' => '邀请码不能为空']);
        }
        $parent = UserModel::get(['request_code' => $request_code]);
        if (!$parent) {
            return json(['errorCode' => 1, 'msg' => '邀请码有误']);
        }
        $parent = $parent->visible(['nickname', 'avatar']);
        return json(['errorCode' => 0, 'msg' => '推荐人信息', 'data' => $parent]);
    }

    //H5注册
    public function register()
    {
        $mobile = input('post.mobile');
        $code = input('post.code');
        $request_code = input('post.request_code');
        $pwd = input('post.pwd');
        $user = UserModel::get(['mobile' => $mobile]);
        if ($user) {
            return json(['errorCode' => 1, 'msg' => '手机号已注册']);
        }
        CodeModel::check($mobile, $code); //验证验证码
        if (empty($request_code)) {
            return json(['errorCode' => 1, 'msg' => '邀请码不能为空']);
        }
        $parent = UserModel::get(['request_code' => $request_code]);
        if (!$parent) {
            return json(['errorCode' => 1, 'msg' => '推荐人不存在']);
        }
        $salt = get_rand_char(6);
        $password = encpwd($pwd, $salt);
//        $new_route = $parent['route'];
        $data = [
            'mobile' => $mobile,
            'password' => $password,
            'salt' => $salt,
            'parentid' => $parent['id'],
            'parent_name' => $parent['nickname'],
//            'route' =>$new_route,
            'team' => 1,
            'depth' => $parent['depth'] + 1,
            'status' => config('status.用户状态_新注册'),//H5注册用户状态 0
            'add_time' => time(),
            'member_time' => time() + config('config.月会员_注册赠送'),
        ];
        Db::startTrans();
        try {
            $result = UserModel::create($data);
            $new_route = $parent['route'] . $result->id . ',';
            $result->route = $new_route;
            $result->save();
            //增加上级粉丝和团队人数
            $parent->fans = $parent['fans'] + 1;
            $parent->save();
            //增加上级团队人数
            UserService::incTeam($parent);
            // 提交事务
            Db::commit();
            return json(['errorCode' => 0, 'msg' => '注册成功', 'data' => $user]);
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            //记录异常
            TransErr::add($e);
            return json(['errorCode' => 1, 'msg' => '注册失败']);
        }

    }

    /**
     * 微信登录
     * @param $openid
     * @param $nickname
     * @param $avatar
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function loginWechat()
    {
        $param = input('post.');
        $device_no = $param['device_no'];//设备号
        $code = $param['code'];
        $wechat_info = (new Wechat())->getInfo($code);
        if (!$wechat_info) {
            return json(['errorCode' => 1, 'msg' => '微信登录失败']);
        }
        $nickname = $wechat_info['nickname'];
        $openid = $wechat_info['openid'];
        $avatar = $wechat_info['headimgurl'];
        $reg_id = DeviceJpush::getRegId($device_no);
        if (isset($param['mobile'])) {
            $mobile = $param['mobile'];
            $user = UserModel::get(['mobile' => $mobile]);
            if ($user) {
                $o_user = UserModel::get(['openid' => $openid]);
                if ($o_user) {
                    return json(['errorCode' => 1, 'msg' => '该微信已绑定其他账号']);
                }
                //H5注册用户绑定微信
                $user->openid = $openid;
                $user->nickname = $nickname;
                $user->avatar = $avatar;
                $user->status = config('status.用户状态_正常');
                $user->token = UserService::generateToken();
                $user->request_code = UserService::generateRequestCode();
                $user->reg_id = $reg_id;
                $res = $user->save();
                if (!$res) {
                    return json(['errorCode' => 1, 'msg' => '绑定微信失败']);
                }
                $user->append(['is_member']);
                return json(['errorCode' => 0, 'msg' => '绑定微信成功', 'data' => $user]);
            } else {
                return json(['errorCode' => 1, 'msg' => '手机号有误']);
            }
        }
        $user = UserModel::get(['openid' => $openid]);
        if (!$user) {
            return json(['errorCode' => 0, 'msg' => '用户不存在', 'data' => ['status' => false, 'info' => $wechat_info]]);  //这个微信没有注册过账号,跳转绑定页面,同时提交
        }
        if ($user['reject'] >= 5) {
            return json(['errorCode' => 1, 'msg' => '账号已被封']);
        }
        $user->nickname = $nickname;
        $user->avatar = $avatar;
        $user->token = UserService::generateToken();
        $user->reg_id = $reg_id;
        $user->save();
        $user->hidden(['id', 'openid', 'bonus_weight']);
        $user->append(['is_member']);
        return json(['errorCode' => 0, 'msg' => '登录成功', 'data' => ['status' => true, 'info' => $user]]);

    }

    //发送验证码判断手机号是否存在
    public function checkMobile()
    {
        $mobile = input('get.mobile');
        $user = UserModel::get(['mobile' => $mobile]);
        if (!$user) {
            return json(['errorCode' => 1, 'msg' => '手机号不存在']);
        }
        return json(['errorCode' => 0, 'msg' => '手机号存在']);
    }

    //手机号登录
    public function loginMobile($mobile, $pwd)
    {
        $user = UserModel::get(['mobile' => $mobile]);
        if (!$user) {
            return json(['errorCode' => 1, 'msg' => '账号密码有误']);
        }
        $encpwd = encpwd($pwd, $user['salt']);
        if ($encpwd != $user['password']) {
            return json(['errorCode' => 1, 'msg' => '账号密码不正确']);
        }
        if ($user['reject'] >= 5) {
            return json(['errorCode' => 1, 'msg' => '账号已被封']);
        }
        $user->token = UserService::generateToken();
        $user->save();
        $user->append(['is_member']);
        return json(['errorCode' => 0, 'msg' => '登录成功', 'data' => $user]);
    }

    //手机号登录--验证码
    public function loginMobileCode($mobile, $code)
    {
        CodeModel::check($mobile, $code);
        $device_no = input('post.device_no');
        $user = UserModel::get(['mobile' => $mobile]);
        if (!$user) {
            return json(['errorCode' => 1, 'msg' => '手机号或验证码错误']);
        }
        if ($user['reject'] >= 5) {
            return json(['errorCode' => 1, 'msg' => '账号已被封']);
        }
        $reg_id = DeviceJpush::getRegId($device_no);
        $user->reg_id = $reg_id;
        $user->token = UserService::generateToken();
        $user->save();
        return json(['errorCode' => 0, 'data' => $user]);
    }

    //刷新用户信息
    public function refreshInfo()
    {
        $token = input('get.token');
        $user = UserModel::get(['token' => $token]);
        if (!$user) {
            return json(['errorCode' => 101, 'msg' => '用户信息获取失败']);
        }
        $user->append(['is_member']);
        //奖金池金额
        $param = Db::name('config_param')->where('key', ['=', 'pool_base'], ['=', 'weight_base'], ['=', 'bonus_pool'], 'or')->column('key,value');
        $user['bonus_pool'] = $param['bonus_pool'] + $param['pool_base'];
//        $user = collection($user)->append('is_member');
        return json(['errorCode' => 0, 'msg' => '刷新用户信息成功', 'data' => $user]);
    }

    //发送验证码
    public function sendSmsCode()
    {
        /*$type = input('post.type');
        $mobile = input('post.mobile');
        if ($type == 1) {
            $user = UserModel::get(['mobile' => $mobile]);
            if (!$user) {
                return json(['errorCode' => 0, 'msg' => '手机号还没有注册,请先注册', 'data' => ['status' => 1, 'msg' => '手机号还没有注册,请先注册']]);
            }
        }
        $response = CodeModel::sendSms($mobile, $type);
        if ($response === false) {
            return json(['errorCode' => 0, 'msg' => '发送失败,请稍后再试', 'data' => ['status' => 1, 'msg' => '短信发送失败']]);
        }
        if ($response->Code == 'OK') {
            return json(['errorCode' => 0, 'msg' => '短信发送成功', 'data' => ['status' => 0, 'msg' => '发送成功']]);
        } else {
            return json(['errorCode' => 0, 'msg' => '发送失败,请稍后再试', 'data' => ['status' => 1, 'msg' => '发送失败,请稍后再试']]);

        }*/

    }

    //绑定手机号和推荐人
    public function bindMobile()
    {
        $param = input('post.');
        $openid = $param['openid'];
        $nickname = $param['nickname'];
        $avatar = $param['avatar'];
        $mobile = $param['mobile'];
        $code = $param['code'];
        $request_code = $param['request_code'];//邀请码
        $device_no = $param['device_no'];
        $pwd = $param['pwd'];
        $m_user = UserModel::get(['mobile' => $mobile]);
        //验证手机号是否已注册
        if ($m_user) {
            return json(['errorCode' => 1, 'msg' => '手机号已绑定其他账号']);
        }
        //验证验证码
        CodeModel::check($mobile, $code);
        //判断邀请人是否存在
        if (empty($request_code)) {
            return json(['errorCode' => 1, 'msg' => '邀请码不能为空']);
        }
        $parent = UserModel::get(['request_code' => $request_code]);
        if (!$parent) {
            return json(['errorCode' => 1, 'msg' => '推荐人不存在']);
        }
        $user = UserModel::get(['openid' => $openid]);
        if ($user) {
            return json(['errorCode' => 1, 'msg' => '用户已存在']);
        }
        $reg_id = DeviceJpush::getRegId($device_no);//获取极光ID

        $salt = get_rand_char(6);
        $password = encpwd($pwd, $salt);
        $data = [
            'openid' => $openid,
            'nickname' => $nickname,
            'avatar' => $avatar,
            'mobile' => $mobile,
            'password' => $password,
            'salt' => $salt,
            'parentid' => $parent['id'],
            'parent_name' => $parent['nickname'],
            'request_code' => UserService::generateRequestCode(),
            'status' => config('status.用户状态_正常'),
            'token' => UserService::generateToken(),
            'reg_id' => $reg_id,
            'add_time' => time(),
            'team' => 1,
            'depth' => $parent['depth'] + 1,
            'member_time' => time() + config('config.月会员_注册赠送'),

        ];
        Db::startTrans();
        try {
            $result = UserModel::create($data);
            $new_route = $parent['route'] . $result->id . ',';
            $result->route = $new_route;
            $result->save();
            //增加上级粉丝人数
            $parent->fans = $parent['fans'] + 1;
            $parent->save();
            //增加上级团队人数
            UserService::incTeam($parent);
            // 提交事务
            Db::commit();
            return json(['errorCode' => 0, 'msg' => '微信注册成功', 'data' => $result]);
        } catch (\Exception $e) {
            Db::rollback();
            return json(['errorCode' => 1, 'msg' => '微信注册失败']);
        }
    }

    //申请成为推广员--脉大师
    public function applyPromoter()
    {
        $user_id = UserService::getUserIdByToken();
        $user = UserModel::get($user_id);
        if ($user['fans'] < 50) {
            return json(['errorCode' => 1, 'msg' => '您团队直推粉丝人数未达到要求']);
        }
        if ($user['is_promoter'] == 1) {
            return json(['errorCode' => 1, 'msg' => '您已经是脉大师']);
        }
        //支付申请费用
        $price = config('config.脉大师_价格');

        $detail = [];

        //充值记录
        $recharge_data = [
            'title' => '申请升级脉大师',
            'user_id' => $user_id,
            'type' => 3,
            'detail' => json_encode($detail, JSON_UNESCAPED_UNICODE),
//            'order_no' => generate_task_no(),
            'order_no' => generate_order_no(),
            'amount' => $price,
            'add_time' => time()
        ];
        Db::name('recharge')->insert($recharge_data);

        $response = Alipay::appPay($recharge_data);
        return json(['errorCode' => 0, 'data' => $response]);
    }

    //申请成为发包方
    public function initiator()
    {
        $user_id = UserService::getUserIdByToken();
        $level = input('post.level');
        $config_str = '_level_' . $level;
        $price = config('config.会员_价格' . $config_str);
        $give_gold = config('config.会员_赠送' . $config_str);

        if ($level == 1) {
            $level_str = '小编';
            $pay_str = '浪莎保暖内衣男士加绒加厚保暖衣冬情侣青年内衣套装女士秋衣秋裤';
        } elseif ($level == 2) {
            $level_str = '主编';
            $pay_str = '浪莎莫代尔秋衣秋裤男士女棉毛衫薄款打底修身本命年保暖内衣套装';
        } else {
            return json(['errorCode' => 1, 'msg' => '参数不正确']);
        }
        $user = UserModel::get($user_id);
        if ($user['level'] >= $level) {
            return json(['errorCode' => 1, 'msg' => '您已经是' . $level_str]);
        }

        //支付成功增加账户金币余额,记录日志

        $detail = [
            'level' => $level,
            'give_gold' => $give_gold
        ];

        //充值记录
        $recharge_data = [
//            'title' => '申请升级' . $level_str,
            'title' => $pay_str,
            'user_id' => $user_id,
            'type' => 2,
            'detail' => json_encode($detail, JSON_UNESCAPED_UNICODE),
//            'order_no' => generate_task_no(),
            'order_no' => generate_order_no(),
            'amount' => $price,
            'add_time' => time()
        ];
        Db::name('recharge')->insert($recharge_data);
        $response = Alipay::appPay($recharge_data);
        return json(['errorCode' => 0, 'data' => $response]);
    }

    //修改发布任务微信信息
    public function updateWechatInfo()
    {
        $user_id = UserService::getUserIdByToken();
        $wechat_id = input('wechat_id');
        $qrcode = request()->file('wechat_qrcode');
        if (empty($wechat_id) || empty($qrcode)) {
            return json(['errorCode' => 1, 'msg' => '参数错误']);
        }
        $user = UserModel::get($user_id);
        if (!empty($user['wechat_id']) || !empty($user['qrcode'])) {
            return json(['errorCode' => 1, 'msg' => '微信信息已添加']);
        }
        $user->wechat_id = $wechat_id;
        //图片上传
        $dir = DS . 'uploads' . DS . 'wechat' . DS . md5($user['openid']);
        $save = ROOT_PATH . 'public' . $dir;
        $info = $qrcode->rule('uniqid')->move($save);
        if ($info) {
            // 成功上传后 获取上传信息
            $image = $dir . DS . $info->getSaveName();
        } else {
            // 上传失败获取错误信息
            return json(['errorCode' => 1, 'msg' => $qrcode->getError()]);
        }
        $user->wechat_qrcode = $image;
        $res = $user->save();
        if ($res === false) {
            return json(['errorCode' => 1, 'msg' => '更新失败']);
        }
        return json(['errorCode' => 0, 'msg' => '更新成功']);
    }


    //修改提现支付宝信息
    public function updateAlipayInfo()
    {
        $user_id = UserService::getUserIdByToken();
        $alipay = input('alipay');
        $realname = input('realname');
        if (empty($alipay) || empty($realname)) {
            return json(['errorCode' => 1, 'msg' => '参数错误']);
        }
        $a_user = UserModel::get(['alipay' => $alipay]);
        if ($a_user) {
            return json(['errorCode' => 1, 'msg' => '该支付宝已经绑定其他账号,请更换支付宝']);
        }
        $user = UserModel::get($user_id);
        if (!empty($user['alipay']) || !empty($user['realname'])) {
            return json(['errorCode' => 1, 'msg' => '提现支付宝信息已添加']);
        }
        $user->alipay = $alipay;
        $user->realname = $realname;
        $res = $user->save();
        if ($res === false) {
            return json(['errorCode' => 1, 'msg' => '更新失败']);
        }
        return json(['errorCode' => 0, 'msg' => '更新成功']);
    }


    /**
     * 我的粉丝
     * @param $page
     * @param $size
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function myFans($page, $size)
    {
        $user_id = input('get.user_id');
        if (!$user_id) {
            $user_id = UserService::getUserIdByToken();
        }
        $fans_list = UserModel::where('parentid', $user_id)->page($page, $size)->order('add_time desc')->select();
//        foreach ($fans_list as &$item) {
////            $count = RecommendModel::team($item['id']);
////            $item['team'] = $count;
//            $item['team'] = 0;
//        }
        return json(['errorCode' => 0, 'msg' => '粉丝列表', 'data' => $fans_list]);
    }

    //金币充值
    public function recharge()
    {
        $user_id = UserService::getUserIdByToken();
        $quantity = input('quantity');
        $price = config('config.金币_单价');
        $min_quantity = config('config.金币_起充');
        if ($quantity < $min_quantity || !is_numeric($quantity) || strpos($quantity, ".") !== false) {
            return json(['errorCode' => 1, 'msg' => '输入金币数量错误']);
        }
        $amount = $quantity * $price;

        //充值记录
        $detail = [
            'gold' => $quantity
        ];
        $recharge_data = [
            'title' => '金币充值',
            'user_id' => $user_id,
            'type' => 1,
            'detail' => json_encode($detail, JSON_UNESCAPED_UNICODE),
//            'order_no' => generate_task_no(),
            'order_no' => generate_order_no(),
            'amount' => $amount,
            'add_time' => time()
        ];
        Db::name('recharge')->insert($recharge_data);

        $response = Alipay::appPay($recharge_data);
//        $response = htmlspecialchars($response);
        return json(['errorCode' => 0, 'data' => $response]);
    }

    /**
     * 金币日志
     * @param $page
     * @param $size
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function logGold($page, $size)
    {
        $user_id = UserService::getUserIdByToken();
        $list = Db::name('gold')->where('user_id', $user_id)->page($page, $size)->field('*')->order('add_time desc')->select();
        return json(['errorCode' => 0, 'data' => $list]);
    }

    /**
     * 余额提现
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function withdrawal()
    {
        $user_id = UserService::getUserIdByToken();
        $realname = input('post.realname');
        $alipay = input('post.alipay');
        $amount = input('post.amount');
        $min_amount = config('config.提现_起提');
        $multiple = config('config.提现_倍数');
        $user = UserModel::get($user_id);
        $is_member = UserService::isMember($user['member_time']);
        if (!$is_member) {
            return json(['errorCode' => 1, 'msg' => '请先到发圈页购买月服务', 'data' => ['status' => 0, 'data' => ['task_time' => 0]]]);
        }
        if (!is_numeric($amount) || strpos($amount, ".") !== false || $amount <= 0) {
            return json(['errorCode' => 1, 'msg' => '输入金额必须是正整数 ']);
        }
        if ($amount % $multiple != 0 || $amount < $min_amount) {
            return json(['errorCode' => 1, 'msg' => '输入金额不正确']);
        }
        if ($amount > $user['money']) {
            return json(['errorCode' => 1, 'msg' => '余额不足']);
        }
        //每天提现一次
        $w_info = Withdrawal::where('user_id', $user_id)->where('status', config('status.提现状态_已提现'))->field('add_time')->order('add_time desc')->find();
        if (date('Ymd', $w_info['add_time']) == date('Ymd')) {
            return json(['errorCode' => 1, 'msg' => '您今天已提现,请明天再提现']);
        }
        $pool_amount = $amount * config('config.提现_扣除_转奖金池');

        $actual_amount = $amount - $pool_amount - config('config.提现_扣除');
        //提现记录
        $data = [
            'order_no' => generate_order_no(),
            'realname' => $realname,
            'alipay' => $alipay,
            'user_id' => $user_id,
            'amount' => $amount,
            'deduct_amount' => config('config.提现_扣除'),
            'pool_amount' => $pool_amount,
            'actual_amount' => $actual_amount,
            'add_time' => time(),
        ];
        //调用支付宝转账
        $res = Alipay::alipayTransfer($data);
        $resultCode = $res->code;
        if (!empty($resultCode) && $resultCode == 10000) {
            //成功
            //账户提现日志
            $log_data = [
                'title' => '提现(实际到账:' . $actual_amount . ')',
                'user_id' => $user_id,
                'task_id' => '',
                'type' => -1,
                'amount' => $amount,
                'add_time' => time()
            ];
            Db::name('money')->insert($log_data);
            //扣除用户金额
            $user->money = $user['money'] - $amount;
            $user->save();
            //转账成功增加奖金池金额
            Db::name('config_param')->where('key', 'bonus_pool')->setInc('value', $pool_amount);
            //提现日志
            $data['alipay_order_id'] = $res->order_id;
            $data['withdrawal_time'] = $res->pay_date;
            $data['status'] = config('status.提现状态_已提现');
            Db::name('withdrawal')->insert($data);
            return json(['errorCode' => 0, 'msg' => '提现提交成功']);
        } else {
            //失败
            //提现日志
            $data['err_msg'] = '【sub_msg:' . $res->sub_msg . '】,【msg:' . $res->msg . '】,【sub_code:' . $res->sub_code . '】';
            $data['status'] = config('status.提现状态_提现失败');
            Db::name('withdrawal')->insert($data);
            if ($res->sub_msg == '付款方余额不足') {
                return json(['errorCode' => 1, 'msg' => '该时段提现额度已满,请下一时段再来']);
            } else {
                return json(['errorCode' => 1, 'msg' => '提现失败']);
            }
        }
    }

    /**
     * 余额日志
     * @param $page
     * @param $size
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function logMoney($page, $size)
    {
        $user_id = UserService::getUserIdByToken();
        $list = Db::name('money')->where('user_id', $user_id)->page($page, $size)->order('add_time desc')->field('*')->select();
        return json(['errorCode' => 0, 'data' => $list]);
    }

    //获取支付宝信息
    public function getAlipayInfo()
    {
        $user_id = UserService::getUserIdByToken();
        $info = UserModel::where('id', $user_id)->field('alipay,realname')->find();
        if (!$info) {
            $info = [
                'realname' => '',
                'alipay' => '',
            ];
        }
        return json(['errorCode' => 0, 'data' => $info]);
    }

    //修改密码
    public function updatePwd()
    {

    }

    //购买月会员
    public function buyMember()
    {
//        return json(['errorCode' => 1, 'msg' => '系统维护升级，5分钟后再试']);
        $user_id = UserService::getUserIdByToken();
        $user = UserModel::get($user_id);
        //支付申请费用
//        $price = config('config.月服务费_价格');
//        $price = 0.01;
        $price = rand(300, 309) / 100;
        $detail = [];

        //充值记录
        $recharge_data = [
            'title' => '浪莎丝袜5条装限时抢购',
            'user_id' => $user_id,
            'type' => 4,
            'detail' => json_encode($detail, JSON_UNESCAPED_UNICODE),
//            'order_no' => generate_task_no(),
            'order_no' => generate_order_no(),
            'amount' => $price,
            'add_time' => time()
        ];
        Db::name('recharge')->insert($recharge_data);

        $response = Alipay::appPay($recharge_data);
        return json(['errorCode' => 0, 'data' => $response]);
    }

}